#ifdef _WIN32
#include <windows.h>

//------------------------------------------------------------------------
csINLINE
csSimpleTimer::csSimpleTimer(bool initAndRun)
:m_startTime(0)
,m_currentTime(0)
,m_stopTime(0)
{
	if(initAndRun)
	{
		QueryPerformanceCounter((LARGE_INTEGER*) &m_startTime);
	}
}

//------------------------------------------------------------------------
csINLINE
csSimpleTimer::~csSimpleTimer()
{

}

//------------------------------------------------------------------------
csINLINE void
csSimpleTimer::start()
{
	csASSERT(!isRunning());
	QueryPerformanceCounter((LARGE_INTEGER*) &m_startTime);
	m_stopTime	= 0;
	m_currentTime	= m_startTime;
}

//------------------------------------------------------------------------
csINLINE void
csSimpleTimer::stop()
{
	csASSERT(isRunning());
	QueryPerformanceCounter((LARGE_INTEGER*) &m_stopTime);
}

//------------------------------------------------------------------------
csINLINE void
csSimpleTimer::reset()
{
	if (isRunning())
	{
		stop();
	}
	m_currentTime = 0;
}

//------------------------------------------------------------------------
csINLINE bool
csSimpleTimer::isRunning() const
{
	return 0!=m_startTime&&0==m_stopTime;
}

//------------------------------------------------------------------------
csINLINE f32
csSimpleTimer::tickElapsed()
{
	csASSERT(isRunning());
	s64 current;
	QueryPerformanceCounter((LARGE_INTEGER*)&current);
	s64 freq;
	QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
	f32 elapsed = (f32)(current-m_currentTime)/(f32)(freq);
	m_currentTime = current;
	return elapsed;
}

//------------------------------------------------------------------------
csINLINE f32
csSimpleTimer::runningTime() const
{
	s64 current;
	if(isRunning())
	{
		QueryPerformanceCounter((LARGE_INTEGER*)&current);
	}
	else
	{
		current = m_stopTime;
	}
	s64 freq;
	QueryPerformanceFrequency((LARGE_INTEGER*) &freq);
	return (f32)(current-m_startTime)/(f32)(freq); 
}
#endif
